package main

import (
	"fmt"
	"gopkg.in/ini.v1"
	"log_transfer/es"
	"log_transfer/kafka"
	"log_transfer/model"
)

//从kafka消费日志数据，写入ES
func main() {
	//1.加载位置文件
	var cfg = new(model.Config)
	err := ini.MapTo(cfg, "./config/logtransfer.ini")
	if err != nil {
		fmt.Printf("load config failed,err:%v\n", err)
		panic(err)
	}
	fmt.Println("load config success")
	//2.连接ES
	fmt.Println("cfg.ESConf.Index:", cfg.ESConf.Index)
	err = es.Init(cfg.ESConf.Address, cfg.ESConf.Index, cfg.ESConf.GoNum, cfg.ESConf.MaxSize) //语法糖
	if err != nil {
		fmt.Printf("Init to es failed,err:%v\n", err)
		panic(err)
	}
	fmt.Println("Init to es success")
	//3.连接kafka
	fmt.Println("cfg.KafkaConf.Address:", cfg.KafkaConf.Address)
	err = kafka.Init([]string{cfg.KafkaConf.Address}, cfg.Topic)
	if err != nil {
		fmt.Printf("Init to kafka failed,err:%v\n", err)
		panic(err)
	}
	fmt.Println("Init to kafka success")

	//select让程序持续运行，不占用cpu
	select {}
}
